package com.jiazhong.basic.shuxin.net;

import lombok.SneakyThrows;

import java.io.InputStream;
import java.net.Socket;

public class DemoD2 {
    @SneakyThrows
    public static void main(String[] args) {
        Socket socket = new Socket("127.0.0.1", 8889);
        InputStream in = socket.getInputStream();
        byte[] bytes = new byte[1024];
        while (true) {
            int len = in.read(bytes);
            String message = new String(bytes, 0, len);
            System.out.println(message);
            if ("bye".equals(message)) {
                break;
            }
        }
    }
}
